import 'base_presenter.dart';
import 'package:flutterclue/utils/SharePreferensUtil.dart';
import 'package:flutterclue/http_util/constant_url.dart';
import 'package:flutterclue/mvp/mode/ClueDetailBean.dart';
import 'package:flutterclue/mvp/mode/ClueEntryDataListBean.dart';

class ClueDetailPagePresenter extends ClueBasePresenter<ClueDetailPageView> {
  getClueDetailData(int clueId) async {
    baseView.showLoadingView();
    Map<String, Object> map = new Map();
    map["AgentId"] =
        await SharePreferencesUtil.getString(SharePreferencesUtil.AgentId);
    map["TopAgentId"] =
        await SharePreferencesUtil.getString(SharePreferencesUtil.TopAgentId);
    map["ClueId"] = "${clueId}";
    await postData(
        url: ApiUrl.ClueDetail_URL,
        params: map,
        error: (error) {
          baseView.dismissLoadingView();
          baseView.onFail(error.toString() == null ? "数据为空" : error.toString());
        }).then((bean) {
      baseView.dismissLoadingView();
      if (bean.Code == 1) {
        ClueDetailBean clueDetailBean = ClueDetailBean.fromJson(bean.Data);
        baseView.onSuccessData(clueDetailBean);
      } else {
        baseView.onFail(bean.Message == null ? "数据为空" : bean.Message);
      }
    });
  }
  getEntryDataList(int clueId) async {
    baseView.showLoadingView();
    Map<String, Object> map = new Map();
    map["AgentId"] =
        await SharePreferencesUtil.getString(SharePreferencesUtil.AgentId);
    map["TopAgentId"] =
        await SharePreferencesUtil.getString(SharePreferencesUtil.TopAgentId);
    map["ClueId"] = "${clueId}";
    await postData(
        url: ApiUrl.CLueEntryList_URL,
        params: map,
        error: (error) {
          baseView.dismissLoadingView();
          baseView.onFail(error.toString() == null ? "数据为空" : error.toString());
        }).then((bean) {
      baseView.dismissLoadingView();
      if (bean.Code == 1) {
        EntryListBean entryListBean=EntryListBean.fromJson(bean.Data);
        baseView.onSuccessListEntry(entryListBean);
      } else {
        baseView.onFail(bean.Message == null ? "数据为空" : bean.Message);
      }
    });
  }
}



abstract class ClueDetailPageView extends BaseView {
  void onFail(String s);

  void onSuccessData(ClueDetailBean clueDetailBean);

  void onSuccessListEntry(EntryListBean entryListBean);
}
